package com.pr.makfilm.core.cmp.web;

import com.pr.makfilm.core.validator.DateFormatValidator;
import org.apache.wicket.Component;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.validation.IValidator;

/**
 * Created by p.radomski on 24.02.14.
 */
public class BootstrapTimePicker extends AbstractBootstrapComponent
{
   private TextField textField;

   public BootstrapTimePicker(String id, IModel<String> model)
   {
      super(id);
      textField = new TextField<String>("timepicker", model);
      textField.add(new DateFormatValidator());
      container.add(textField);
   }

   @Override
   public void setValidation(boolean required)
   {
      textField.setRequired(required);
   }

   public void addValidator(IValidator validator)
   {
      textField.add(validator);
   }

   @Override
   public void renderHead(IHeaderResponse response)
   {
      response.render(OnDomReadyHeaderItem.forScript("timepicker();"));
   }

   @Override
   public Component getField()
   {
      return textField;
   }
}
